import React,{useState} from 'react'

export default function Counter(props) {
  /*
    如果以函数的方式作为useState的参数，那么个函数的返回值将作为变量的初始值
  */
  const [count,setCount]=useState(()=>{
    return props.initNum+1
  })
  const increment=()=>{
    setCount(count+1)
  }
  return (
    <div>
       <h1>{count}</h1>
       <button onClick={increment}>+</button>
    </div>
  )
}
